package com.gxa.community.customer.controller.order;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.gxa.community.core.pojo.bo.order.OrderAndGoodsInfo;
import com.gxa.community.core.pojo.vo.order.UserAndAgentAndGoodsInfoVO;
import com.gxa.community.customer.service.order.OrderService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 无论是在单个商品页面点击立即购买，还是在购物车页面点击去下单
     * 都需要先根据前端传入的当前用户id  去查询用户的相关信息
     * 提货人、自提点、优惠券、
     */
    @ApiOperation("查询下单用户信息及优惠券、提货人、自提点信息的接口")
    @GetMapping("/pricreateorder")
    public String preCreateOrder(Integer userId){
        String s = orderService.preCreateOrder(userId);
        return s;
    }

    /**
     * 两种下单，单独的商品页面下单，   购物车页面下单
     * @param userAndAgentAndGoodsInfoVO
     * @return
     * @throws JsonProcessingException
     */


    @ApiOperation("创建订单")
    @PostMapping("/createorder")
    public String createOrder(@RequestBody UserAndAgentAndGoodsInfoVO userAndAgentAndGoodsInfoVO) throws JsonProcessingException {
        String order = orderService.createOrder(userAndAgentAndGoodsInfoVO);
        return order;
    }

    @ApiOperation("取消订单")
    @PostMapping
    public String cancelOrder(){
        return null;
    }

}
